package com.zzh;

import java.util.HashMap;
import java.util.Map;

public class MapPractice {
    public static void main(String[] args) {
        Map<String,String> data = new HashMap<>();
        data.put("张三", "A");
        data.put("李四", "B");
        data.put("王五", "C");
        data.put("赵六", "D");
        data.put("孙七", "B");
        data.put("QQ", "A");
        data.put("ZZ", "C");
        data.put("XX", "D");
        data.put("YY", "B");
        data.put("PP", "A");
        data.put("MM", "C");
        data.put("HH", "D");
        data.put("GG", "B");
        data.put("FF", "A");
        data.put("EE", "C");
        data.put("DD", "D");
        data.put("CC", "B");
        data.put("BB", "D");
        data.put("AA", "B");
        data.put("WW", "D");
        data.put("VV", "A");
        data.put("SS", "C");



        count(data);
    }

    private static void count(Map<String, String> data) {
        /*
        1.创建一个Map集合，储存投票结果
        2.遍历data集合
        3.将value拿出来，value作为key存到新的集合中
        4.若集合中不存在，则添加并设值为1，若存在，则值+1
         */
        Map<String,Integer> resultMap = new HashMap<>();
        data.forEach((k,v)->{
            boolean containsKey =resultMap.containsKey(v);
            if(!containsKey){
                resultMap.put(v,1);
            }else{
                Integer oldCount = resultMap.get(v);
                resultMap.put(v,oldCount+1);
            }

        });

        resultMap.forEach((k,v)->{
            System.out.println(k+"--->"+v);
        });
    }
}
